#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<sys/types.h>

#include <python2.7/Python.h>


extern void cmd_blescan(void);
char a[20] = {0};
char *sum = a;
char oldsum[20] = {0};
void python()
{	
	PyObject *pModule = NULL, *pDict = NULL, *pFunc = NULL, *pArg = NULL, *result = NULL;
	Py_Initialize();
	// 将当前目录加入sys.path
	PyRun_SimpleString("import sys");
	PyRun_SimpleString("sys.path.append('./')");
	// 导入hello.py模块
	pModule = PyImport_ImportModule("ble"); //引入模块
	pDict = PyModule_GetDict(pModule); //获取模块字典属性 //相当于Python模块对象的__dict__ 属性，得到模块名称空间下的字典对象
	pFunc = PyDict_GetItemString(pDict, "m_scan"); //从字典属性中获取函数
	pArg = Py_BuildValue("(s, s)", "a", "b"); //参数类型转换，传递两个整型参数
	result = PyEval_CallObject(pFunc, pArg); //调用函数，并得到python类型的返回值
	PyArg_Parse(result, "s", &sum); //将python类型的返回值转换为c/c++类型
	Py_Finalize();
}
int main()
{         
    while(1)
    {    
      python();
      if(sum != NULL && strcmp(oldsum,sum)!=0)
      {
         printf("sum=%s\n", sum);
         strcpy(oldsum,sum);
		 /*这里进行你的操作*/
      }			  
    }
}